# 对一篇英文小说，进行词频统计，输出前20个出现频率最高的单词；
def getText():
    txt = open("The Old Man And the Sea.txt","r",encoding='utf-8').read()
    txt = txt.lower()
    for ch in '!"#$&()*+,-./:;<=>?@[\\]^_{|}·~‘’':
        txt = txt.replace(ch," ")
    return txt


if __name__ == '__main__':
    txt = getText()
    words = txt.split()
    counts = {}
    for word in words:
        counts[word] = counts.get(word,0) + 1

    items = list(counts.items())
    items.sort(key=lambda x: x[1], reverse=True)
    for i in range(20):
        word, count = items[i]
        print("{0:<10}{1:>5}".format(word, count))
